import { Module } from '@nestjs/common';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { join } from 'path';
import { UploadController } from './upload.controller';
import { UserService } from '../user/user.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from '../user/models/user.entity';
import { Student } from '../student/models/student.entity';
import { StudentService } from '../student/student.service';

@Module({
  imports: [
    MulterModule.register({
      storage: diskStorage({
        destination: join(__dirname, '../../../public/uploaded'),
        filename: (_, file, callback) => {
          const fileName = file.originalname;
          return callback(null, fileName);
        },
      }),
    }),
    TypeOrmModule.forFeature([User, Student]),
  ],
  controllers: [UploadController],
  providers: [UserService, StudentService],
  exports: [UserService, StudentService],
})
export class UploadModule {}
